package net.simflow.swf.analyzer.exec.stats.opt;

import net.simflow.swf.analyzer.exec.data.ExecResult;
import net.simflow.swf.analyzer.exec.stats.data.ExecStats;

public class ExecStatsAnalyzer {

	private static ExecStatsAnalyzer instance = new ExecStatsAnalyzer();

	private ExecStatsAnalyzer() {
	}

	public static ExecStatsAnalyzer getInstance() {
		return instance;
	}

	public ExecStats analyze(ExecResult execResult) {
		ExecStats stats = new ExecStats();

		stats.setExecResult(execResult);
		stats.setExecTimeDistribution(ExecTimeDistributionAnalyzer
				.getInstance().analyze(execResult.getTaskExecMap()));
		stats.setServiceTotalCountMap(ServiceCountAnalyzer.getInstance()
				.analyzeTotalCount(
						execResult.getNetwork().getServiceMap().values()));
		stats.setServiceExecCountMap(ServiceCountAnalyzer.getInstance()
				.analyzeExecCount(
						execResult.getNetwork().getServiceMap().values()));
		stats.setServiceUnfinishedCountMap(ServiceCountAnalyzer.getInstance()
				.analyzeUnfinishCount(
						execResult.getNetwork().getServiceMap().values()));
		stats.setServiceTotalCountDistribution(ServiceCountAnalyzer
				.getInstance().analyzeDistribution(
						stats.getServiceTotalCountMap()));
		stats.setServiceExecCountDistribution(ServiceCountAnalyzer
				.getInstance().analyzeDistribution(
						stats.getServiceExecCountMap()));
		stats.setServiceUnfinishedCountDistribution(ServiceCountAnalyzer
				.getInstance().analyzeDistribution(
						stats.getServiceUnfinishedCountMap()));
		stats.setServiceWaitTimeMap(ServiceWaitTimeAnalyzer.getInstance()
				.analyzeWaitTime(
						execResult.getNetwork().getServiceMap().values()));
		stats.setServiceMaxWaitTimeDistribution(ServiceWaitTimeAnalyzer
				.getInstance().analyzeMaxWaitTimeDistribution(
						stats.getServiceWaitTimeMap()));
		stats.setServiceMinWaitTimeDistribution(ServiceWaitTimeAnalyzer
				.getInstance().analyzeMinWaitTimeDistribution(
						stats.getServiceWaitTimeMap()));
		stats.setServiceAvgWaitTimeDistribution(ServiceWaitTimeAnalyzer
				.getInstance().analyzeAvgWaitTimeDistribution(
						stats.getServiceWaitTimeMap()));
		stats.setServiceOverAbilityTimeMap(ServiceOverAbilityTimeAnalyzer
				.getInstance().analyzeOverAbilityTime(
						execResult.getNetwork().getServiceMap().values()));
		stats.setServiceOverAbilityTimeDistribution(ServiceOverAbilityTimeAnalyzer
				.getInstance().analyzeOverAbilityTimeDistribution(
						stats.getServiceOverAbilityTimeMap()));
		stats.setFlowTotalCountMap(FlowCountAnalyzer.getInstance()
				.analyzeTotalTask(stats.getExecResult().getTaskExecMap()));
		stats.setFlowExecCountMap(FlowCountAnalyzer.getInstance()
				.analyzeExecTask(stats.getExecResult().getTaskExecMap()));
		stats.setFlowUnfinishedCountMap(FlowCountAnalyzer.getInstance()
				.analyzeUnfinishedTask(stats.getExecResult().getTaskExecMap()));
		stats.setFlowTotalCountDistribution(FlowCountAnalyzer.getInstance()
				.analyzeDistribution(stats.getFlowTotalCountMap()));
		stats.setFlowExecCountDistribution(FlowCountAnalyzer.getInstance()
				.analyzeDistribution(stats.getFlowExecCountMap()));
		stats.setFlowUnfinishedCountDistribution(FlowCountAnalyzer
				.getInstance().analyzeDistribution(
						stats.getFlowUnfinishedCountMap()));
		stats.setFlowOverAbilityTimeMap(FlowOverAbilityTimeAnalyzer
				.getInstance().analyzeOverAbilityTime(
						execResult.getNetwork().getFlowMap().values()));
		stats.setFlowOverAbilityTimeDistribution(FlowOverAbilityTimeAnalyzer
				.getInstance().analyzeOverAbilityTimeDistribution(
						stats.getFlowOverAbilityTimeMap()));
		stats.setFlowExecTimeMap(FlowExecTimeAnalyzer.getInstance()
				.analyzeExecTime(
						stats.getExecResult().getTaskExecMap().values()));
		stats.setFlowMaxExecTimeDistribution(FlowExecTimeAnalyzer.getInstance()
				.analyzeMaxExecTimeDistribution(stats.getFlowExecTimeMap()));
		stats.setFlowMinExecTimeDistribution(FlowExecTimeAnalyzer.getInstance()
				.analyzeMinExecTimeDistribution(stats.getFlowExecTimeMap()));
		stats.setFlowAvgExecTimeDistribution(FlowExecTimeAnalyzer.getInstance()
				.analyzeAvgExecTimeDistribution(stats.getFlowExecTimeMap()));

		return stats;
	}
}
